package tests;

import static org.junit.Assert.*;

import org.junit.Test;

import fourWins.Chip;
import fourWins.Game;
import fourWins.Result;

public class MainTest {

	@Test
	public void test() {
		Game game = new Game(6,7);
		Chip chip = new Chip(1);
		
		Result result = game.throwChip(chip, 0);
		assertTrue(result instanceof Result);
	}
	
	@Test
	public void testResult(){
		Result result = new Result();
		assertEquals((int)0, result.isWinner());
	}
	
	@Test
	public void testResultWinVertical1(){
		Result result = new Result();
		Game game = new Game(6,7);
		Chip chip = new Chip(1);
		
		
		result = game.throwChip(chip, 0);
		assertEquals((int)0, result.isWinner());
		result = game.throwChip(chip, 0);
		assertEquals((int)0, result.isWinner());
		result = game.throwChip(chip, 0);
		assertEquals((int)0, result.isWinner());
		result = game.throwChip(chip, 0);
		assertEquals((int)1, result.isWinner());
		game.printField("testResultWinVertical1");
	}
	@Test
	public void testResultWinVertical2(){
		Result result = new Result();
		Game game = new Game(6,7);
		Chip chip2 = new Chip(2);
		
		result = game.throwChip(chip2, 6);
		assertEquals((int)0, result.isWinner());
		result = game.throwChip(chip2, 6);
		assertEquals((int)0, result.isWinner());
		result = game.throwChip(chip2, 6);
		assertEquals((int)0, result.isWinner());
		result = game.throwChip(chip2, 6);
		assertEquals((int)2, result.isWinner());
		game.printField("testResultWinVertical2");
	}
	@Test
	public void testResultWinVertical3(){
		Result result = new Result();
		Game game = new Game(6,7);
		Chip chip1 = new Chip(1);
		Chip chip2 = new Chip(2);
		
		result = game.throwChip(chip1, 6);
		result = game.throwChip(chip1, 6);
		result = game.throwChip(chip2, 6);
		assertEquals((int)0, result.isWinner());
		result = game.throwChip(chip2, 6);
		assertEquals((int)0, result.isWinner());
		result = game.throwChip(chip2, 6);
		assertEquals((int)0, result.isWinner());
		result = game.throwChip(chip2, 6);
		assertEquals((int)2, result.isWinner());
		game.printField("testResultWinVertical3");
	}
	@Test
	public void testResultWinHorizontal(){
		Result result = new Result();
		Game game = new Game(6,7);
		Chip chip = new Chip(1);
		
		
		result = game.throwChip(chip, 1);
		assertEquals((int)0, result.isWinner());
		result = game.throwChip(chip, 2);
		assertEquals((int)0, result.isWinner());
		result = game.throwChip(chip, 3);
		assertEquals((int)0, result.isWinner());
		result = game.throwChip(chip, 4);
		assertEquals((int)1, result.isWinner());
		
		game.printField("testResultWinHorizontal");
	}
	
	@Test
	public void testResultWinDiagonalFromTopLeftToBottomRight(){
		Result result = new Result();
		Game game = new Game(6,7);
		Chip chip1 = new Chip(1);
		Chip chip2 = new Chip(2);
		
		result = game.throwChip(chip1, 0);
		result = game.throwChip(chip2, 2);
		result = game.throwChip(chip1, 0);
		result = game.throwChip(chip2, 0);
		result = game.throwChip(chip1, 1);
		result = game.throwChip(chip2, 1);
		result = game.throwChip(chip1, 0);
		result = game.throwChip(chip2, 4);
		result = game.throwChip(chip1, 1);
		result = game.throwChip(chip2, 0);
		result = game.throwChip(chip1, 2);
		result = game.throwChip(chip2, 1);
		result = game.throwChip(chip1, 3);
		game.printField("FromTopLeftToBottomRight");
		assertEquals((int)1, result.isWinner());
	}
	@Test
	public void testResultWinDiagonalFromBottomLeftToTopRight(){
		Result result = new Result();
		Game game = new Game(6,7);
		Chip chip1 = new Chip(1);
		Chip chip2 = new Chip(2);
		
		result = game.throwChip(chip1, 0);
		result = game.throwChip(chip2, 1);
		result = game.throwChip(chip1, 1);
		result = game.throwChip(chip2, 2);
		result = game.throwChip(chip1, 2);
		result = game.throwChip(chip2, 3);
		result = game.throwChip(chip1, 2);
		result = game.throwChip(chip2, 3);
		result = game.throwChip(chip1, 3);
		result = game.throwChip(chip2, 4);
		result = game.throwChip(chip1, 3);

		game.printField("FromBottomLeftToTopRight");
		assertEquals((int)1, result.isWinner());
	}
	@Test
	public void testWinnerRandom(){
		Game game = new Game(6,7);
		Chip chip1 = new Chip(1);
		Chip chip2 = new Chip(2);
		
		assertEquals((int)0, game.throwChip(chip1, 0).isWinner());
		assertEquals((int)0,  game.throwChip(chip2, 1).isWinner());
		assertEquals((int)0,  game.throwChip(chip1, 2).isWinner());
		assertEquals((int)0,  game.throwChip(chip2, 3).isWinner());
		assertEquals((int)0,  game.throwChip(chip1, 4).isWinner());
		assertEquals((int)0,  game.throwChip(chip2, 5).isWinner());
		assertEquals((int)0,  game.throwChip(chip1, 6).isWinner());
		assertEquals((int)0,  game.throwChip(chip2, 1).isWinner());
		assertEquals((int)0,  game.throwChip(chip1, 3).isWinner());
		assertEquals((int)0,  game.throwChip(chip2, 4).isWinner());
		assertEquals((int)0,  game.throwChip(chip1, 5).isWinner());
		assertEquals((int)0,  game.throwChip(chip1, 0).isWinner());
		assertEquals((int)0,  game.throwChip(chip2, 1).isWinner());
		assertEquals((int)0,  game.throwChip(chip1, 2).isWinner());
		assertEquals((int)0,  game.throwChip(chip2, 3).isWinner());
		assertEquals((int)0,  game.throwChip(chip1, 4).isWinner());
		assertEquals((int)0,  game.throwChip(chip2, 5).isWinner());
		assertEquals((int)0,  game.throwChip(chip1, 6).isWinner());
		assertEquals((int)2,  game.throwChip(chip2, 1).isWinner());
		assertEquals((int)1,  game.throwChip(chip1, 3).isWinner());
		assertEquals((int)0,  game.throwChip(chip2, 4).isWinner());
		assertEquals((int)0,  game.throwChip(chip1, 2).isWinner());
		assertEquals((int)0,  game.throwChip(chip2, 3).isWinner());
		assertEquals((int)1,  game.throwChip(chip1, 2).isWinner());
		assertEquals((int)2,  game.throwChip(chip2, 1).isWinner());
		assertEquals((int)1,  game.throwChip(chip1, 2).isWinner());
		assertEquals((int)2,  game.throwChip(chip2, 2).isWinner());

		game.printField("testWinnerRandom");
	}
	@Test
	public void TTTcreateNewGame(){
		Game game = new Game(3,3);
		game.printField("TTT - empty field");
		assertTrue(game instanceof Game);
	}
	
	@Test
	public void TTTthrowChip(){
		Game game = new Game(3,3);
		Chip chip1 = new Chip(1);
		Result result = game.setChip(chip1, 0, 0);
		game.printField("TTT - chip at 0 0");
		assertTrue(result instanceof Result);
	}
	
	@Test
	public void TTTWinHorizontal1(){
		Game game = new Game(3,3);
		Chip chip1 = new Chip(1);
		assertEquals((int)0,  game.setChip(chip1, 0, 0).isWinner());
		assertEquals((int)0,  game.setChip(chip1, 1, 0).isWinner());
		assertEquals((int)1,  game.setChip(chip1, 2, 0).isWinner());
		
		
	}
	
	@Test
	public void TTTWinVertical1(){
		Game game = new Game(3,3);
		Chip chip1 = new Chip(1);
		assertEquals((int)0,  game.setChip(chip1, 0, 0).isWinner());
		assertEquals((int)0,  game.setChip(chip1, 0, 1).isWinner());
		assertEquals((int)1,  game.setChip(chip1, 0, 2).isWinner());
		game.printField("TTT - winner left col");
	}
	
	@Test
	public void TTTWinDiagonal1(){
		Game game = new Game(3,3);
		Chip chip1 = new Chip(1);
		assertEquals((int)0,  game.setChip(chip1, 0, 0).isWinner());
		assertEquals((int)0,  game.setChip(chip1, 1, 1).isWinner());
		assertEquals((int)1,  game.setChip(chip1, 2, 2).isWinner());
		game.printField("TTT - winner diagnoal 1");
	}
}
